<template>
	<view class="container">
		<u-sticky>
			<u-navbar leftText="" :title="albumName" :safeAreaInsetTop="true" :placeholder="true">
				<view class="u-nav-slot" slot="left" @click="goBack()">
					<u-icon name="arrow-left" size="19"></u-icon>
				</view>
			</u-navbar>
		</u-sticky>
		<view class="container-content">
			<view class="all-container">
				<view class="all-images-container">
					<image v-for="(url, index) in urls2" :key="index" :src="url" mode="aspectFill" class="all-image"
						@click="previewImage(url, urls2)">
					</image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getOwnPostImages
	} from '@/request/api.js'
	export default {
		data() {
			return {
				albumName: '', //传入的相册名称信息
				urls2: [],
				singleSizeWidth: 180, //相册单图模式图片宽度
				multipleSizeWidth: 70, //相册多图模式图片宽度
				currentSwiperIndex: {}, // 年份轮播索引
				currentMonthSwiperIndex: {}, // 月份轮播索引
				targetImageUrl: '', // 用于存储需要定位的图片URL
				// 修改这里：使用对象来存储每个月份的高亮图片URL
				highlightedImageUrls: {
					single: {}, // 存储每个年月组合的单图高亮URL
					three: {}, // 存储每个年月组合的三图高亮URL
					four: {} // 存储每个年月组合的四图高亮URL
				},
			}
		},

		onLoad(option) {
			if (option.name) this.albumName = option.name;
			this.urls2 = uni.getStorageSync('albumPicture')
			const systemInfo = uni.getSystemInfoSync();
			const screenWidth = systemInfo.windowWidth;
			this.singleSizeWidth = screenWidth - 30
			this.multipleSizeWidth = (screenWidth - 42) / 3

		},
		methods: {
			goBack() {
				uni.navigateBack()
			},


			// 图片预览功能
			previewImage(currentUrl, urls) {
				uni.previewImage({
					current: currentUrl,
					urls: urls
				});
			},

			handleTo(num) {
				switch (num) {
					case 1: //分享
						uni.showToast({
							title: '分享',
							icon: 'none'
						});
						break;
					case 2: //置顶
						uni.showToast({
							title: '置顶',
							icon: 'none'
						});
						break;
					case 3: //删除
						uni.showToast({
							title: '删除',
							icon: 'none'
						});
						break;
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		background-color: #fff;
		margin: 0 30rpx;


		.container-tabs {
			height: 100rpx;
			border-radius: 40rpx;
			background-color: rgba(235, 235, 235, 1);
			display: flex;
			text-align: center;

			.tab-item {
				width: 50%;
				height: 80rpx;
				line-height: 80rpx;
				margin: 10rpx;
				border-radius: 40rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				cursor: pointer;
				background-color: transparent; // 默认背景透明
				transition: background-color 0.3s; // 添加过渡效果
				font-weight: 400;

				&.active {
					background-color: #fff; // 激活状态背景为白色
					font-weight: 800;
				}

				&-image {
					width: 40rpx;
					margin-right: 12rpx;
					margin-top: 10rpx;

					image {
						width: 40rpx;
						height: 40rpx;
					}
				}

				&-text {
					color: rgba(41, 41, 48, 1);
					font-size: 26rpx;
				}
			}
		}

		.container-content {
			margin-top: 40rpx;
			padding-bottom: 40rpx;

			.album {
				@include flex;
				align-items: flex-start;

				&__avatar {
					background-color: $u-bg-color;
					padding: 5px;
					border-radius: 3px;
				}

				&__content {
					margin-left: 10px;
					flex: 1;
				}
			}

			// 按年展示，每年只展示一张
			// .year-container {
			// 	.year-section {
			// 		margin-bottom: 30rpx;

			// 		.year-title {
			// 			font-size: 32rpx;
			// 			font-weight: bold;
			// 			margin-bottom: 20rpx;
			// 			color: #333;
			// 		}

			// 		.image-item {
			// 			width: 100%;
			// 			margin-bottom: 20rpx;

			// 			.year-image {
			// 				width: 100%;
			// 				height: calc(100vw * 3 / 4); // 4:3 宽高比
			// 				border-radius: 10rpx;
			// 			}
			// 		}
			// 	}
			// }

			// 按年分组，轮播展示
			.year-container {
				.year-section {
					margin-bottom: 40rpx;

					.swiper-container {
						position: relative;
						border-radius: 10rpx;
						overflow: hidden;

						.swiper-image {
							width: 100%;
							height: 400rpx;
						}

						// 年份标题覆盖层样式
						.year-title-overlay {
							text-align: left;
							position: absolute;
							top: 20rpx;
							left: 20rpx;
							z-index: 20;
							color: white;
							font-size: 36rpx;
							line-height: 40rpx;
							font-weight: 700;
							padding: 10rpx 20rpx;
							text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
							// backdrop-filter: blur(10rpx);
						}

						.month-title-overlay {
							text-align: left;
							position: absolute;
							top: 70rpx;
							left: 20rpx;
							z-index: 20;
							color: white;
							font-size: 30rpx;
							font-weight: bold;
							line-height: 30rpx;
							padding: 10rpx 20rpx;
							text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
							// backdrop-filter: blur(10rpx);
						}
					}
				}
			}

			// 按月份分组展示
			.month-container {
				.month-section {
					margin-bottom: 40rpx;

					// 年月标题样式
					.year-month-title {
						font-size: 36rpx;
						font-weight: 700;
						color: #333;
						margin-bottom: 20rpx;
						padding-left: 10rpx;
					}

					// 月份内容容器
					.month-content {
						border-radius: 10rpx;
						overflow: hidden;
						position: relative;

						// 单张图片布局
						&.single {
							.single-layout {
								position: relative;

								.single-image {
									width: 100%;
									height: 400rpx;
									border-radius: 10rpx;
								}
							}
						}

						// 三张图片布局（左边一张，右边两张）
						&.three {
							height: 440rpx;

							.three-layout {
								display: flex;
								height: 100%; // 占满容器高度

								.left-image {
									flex: 1;
									margin-right: 10rpx;

									.large-image {
										width: 100%;
										height: 100%;
										border-radius: 10rpx;
									}
								}

								.right-images {
									flex: 1;
									display: flex;
									flex-direction: column;
									justify-content: space-between;

									.small-image {
										width: 100%;
										flex: 1;
										border-radius: 10rpx;
										margin-bottom: 10rpx;

										&:last-child {
											margin-bottom: 0;
										}
									}
								}
							}
						}

						// 四张图片布局（上面一张大图，下面三张小图）
						&.four {
							height: 660rpx; // 400rpx(大图) + 10rpx(间距) + 210rpx(小图) + 40rpx(上下padding) = 660rpx

							.four-layout {
								height: 100%;

								.top-image {
									height: 400rpx; // 大图高度

									.large-image {
										width: 100%;
										height: 100%;
										border-radius: 10rpx;
									}
								}

								.bottom-images {
									display: flex;
									justify-content: space-between;
									margin-top: 10rpx; // 添加顶部间距

									.small-image {
										width: 32%;
										height: 210rpx; // 小图高度
										border-radius: 10rpx;
									}
								}
							}
						}
					}
				}
			}

			// 全部
			.all-container {
				.all-images-container {
					display: flex;
					flex-wrap: wrap;

					// justify-content: space-between;
					.all-image {
						width: calc((100% - 20rpx) / 3);
						height: 200rpx;
						border-radius: 10rpx;
						margin-bottom: 10rpx;
						box-sizing: border-box;
						margin-right: 10rpx;

						&:nth-child(3n) {
							margin-right: 0; // 每行第三个元素不需要右边距
						}
					}
				}
			}

			.container-footer {
				position: fixed;
				width: calc(100% - 180rpx);
				bottom: 54rpx;
				left: 90rpx;
				height: 100rpx;
				border-radius: 40rpx;
				background-color: rgba(230, 230, 230, 0.65);
				display: flex;
				text-align: center;

				.container-footer-item {
					width: 50%;
					height: 80rpx;
					line-height: 80rpx;
					margin: 10rpx;
					border-radius: 40rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					cursor: pointer;
					background-color: transparent; // 默认背景透明
					transition: background-color 0.3s; // 添加过渡效果
					font-weight: 400;

					&.active {
						background-color: rgba(94, 94, 94, 0.8); // 激活状态背景为白色
						font-weight: 800;
						color: #fff;
					}
				}
			}
		}
	}
</style>